<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>代理模式</title>
</head>
<body>
<script>
    const obj = {
        name: 'proxy',
        age: 18,
        greet: function(message) {
            console.log(Object.values(this)[Symbol.iterator]());
            return `${message}, ${this.name}!`;
        },
        [Symbol.iterator]: function () {
            return Object.values(this)[Symbol.iterator]();
        }
    }
    const proxy = new Proxy(obj, {
        get(target, key, receiver) {
            return Reflect.get(target, key, receiver)
        },
        set(target, key, value) {
            Reflect.set(target, key, value)
        },
        deleteProperty(target, key) {
            if (key === 'name') {
                console.log('不能删除 name 属性');
                return false;
            }
            return Reflect.deleteProperty(target, key)
        }
    })
    console.log(proxy.name);
    proxy.name = 'proxy1'
    delete proxy.name
    const [name, age] = obj
    console.log(name);
    console.log(age);
    proxy.greet('eee')
    console.log(obj[Symbol.iterator]);
</script>
</body>
</html>
